/**
* 头部菜单
*/ 
<style>
/* 修改全局菜单展开 */
.el-menu--popup-bottom-start {
  margin-right: 15px;
}
</style>
<template>
  <el-menu
    class="el-menu-demo"
    mode="horizontal"
    text-color="#ccc"
    active-text-color="#f00"
  >
    <div
      v-if="
        $store.state.systemLayer == 'front' &&
        !(
          $route.path.indexOf('enterprise') !== -1 ||
          $route.path.indexOf('opportunity') !== -1 ||
          $route.path.indexOf('workRecord') !== -1 ||
          $route.path.indexOf('contactsList') !== -1
        )
      "
      class="head_left"
    >
      <!-- 统计条件 -->
      <!-- <div id="statistics">
        <el-input
          placeholder="搜索联系人、企业、企微会话内容等"
          v-model="homeSearch"
          class="input-with-select"
          size="mini"
        >
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </div> -->
      <el-button
        style="margin-left: 8px"
        icon="el-icon-plus"
        type="primary"
        size="mini"
        @click="showEditer(0)"
        >新增联系人</el-button
      >
      <el-button
        style="margin-left: 8px"
        icon="el-icon-plus"
        size="mini"
        type="primary"
        @click="showFollow(0)"
        >新增跟进信息</el-button
      >
    </div>
    <div id="head">
      <el-dropdown>
        <div style="display: flex; align-items: center">
          <img
            style="border-radius: 40px"
            class="headImg"
            id="userimg"
            :src="urlimg"
            alt=""
          />
          <div class="user_name_c">
            <span>{{ userName !== "" ? userName : "管理员" }}</span>
          </div>
          <!-- <i class="el-icon-arrow-down el-icon--right"></i> -->
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item
            >
            <!-- <span @click="system()">{{ sysName }}</span> -->
            </el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>

      <!-- <div class="nactione"></div>
      <img src="../assets/img/head.png" alt="" class="headImg" />
      <div class="user_name_c">
        <span>管理员</span>
      </div>
      <el-submenu index="2" class="submenu" collapse-transition="true">
        <div id="set">
          <el-menu-item @click="system()" index="1-1" class="centers">
            <i class="el-icon-setting"></i>{{ sysName }}
          </el-menu-item>
        </div>
      </el-submenu> -->
    </div>
  </el-menu>
</template>
<script>
import { localStorageSet, localStorageGet } from "../api/axiosFun";
import { agentId, corpsecret } from "../../config/http";
export default {
  name: "navcon",
  data() {
    return {
      urlimg: localStorage.getItem("avatar"),
      userName: localStorage.getItem("name"), // 用户名
      sysName: "",
      collapsed: true,
      imgshow: require("../assets/img/show.png"),
      imgsq: require("../assets/img/sq.png"),
      user: {},
      notify: {}, //消息通知
      homeSearch: "", // 搜索内容
      // 客户
      customer: {
        contacts: "",
        company: "",
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      data: {},
    };
  },
  created() {
    let that = this;
    // 网页授权链接
    // var address = window.location.href;
    // var addresss = address.split("?");
    // if (addresss.length <= 1) {
    //   this.$cmsapi.redirectUrl("http://scrm.lyqswl.com").then(
    //     (res) => {
    //       if (res.code == 0) {
    //         window.location.href = res.data;
    //       } else {
    //         this.$message.error(res.msg);
    //       }
    //     },
    //     (err) => {
    //       console.log(err);
    //     }
    //   );
    // } else if (!localStorage.getItem("userid")) {
    //   // 企微重定向之后操作
    //   let url = window.location.href;
    //   let p = url.split("?")[1];
    //   let params = new URLSearchParams(p);
    //   alert(params.get("code")); //1
    //   this.$cmsapi.UserLand(params.get("code")).then(
    //     (res) => {
    //       console.log(res);
    //       if (res.code == 0) {
    //         localStorage.setItem("userid", res.data.userid);
    //         localStorage.setItem("token", res.data.token);
    //         localStorage.setItem("name", res.data.name);
    //         localStorage.setItem("avatar", res.data.avatar);
    //         // $("#userimg").src = res.data.avatar;
    //         // this.userName = res.data.name;
    //       } else {
    //         alert("获取失败", res);
    //         this.$message.error(res.msg);
    //       }
    //     },
    //     (err) => {
    //       console.log(err);
    //     }
    //   );
    // }
    
    // this.$cmsapi.agentConfig(window.location.href.split("?")[0]).then(
    //   (res) => {
    //     if (res.code == 0) {
    //       wx.config({
    //         beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
    //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    //         appId: res.data.corpid, // 必填，企业微信的corpID
    //         timestamp: res.data.timestamp, // 必填，生成签名的时间戳
    //         nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
    //         signature: res.data.signature, // 必填，签名，见 附录-JS-SDK使用权限签名算法
    //         jsApiList: ["openDefaultBrowser", "config"], // 必填，需要使用的JS接口列表，凡是要调用的接口都需要传进来
    //       });
    //       wx.ready(function () {
    //         that.openDefaultBrowserFs();
    //       });

    //       wx.error(function (res) {
    //         // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
    //         console.log(res);
    //       });
    //     } else {
    //       this.$message.error(res.msg);
    //     }
    //   },
    //   (err) => {
    //     console.log("本地接口", err);
    //   }
    // );
    if (this.$store.state.systemLayer == "front") {
      this.sysName = "后台管理系统";
      document.title = "群思SCRM-PC";
    } else {
      this.sysName = "前台管理系统";
      document.title = "群思SCRM-后台";
    }
    this.user = JSON.parse(localStorage.getItem("userdata"));
  },
  methods: {
    openDefaultBrowserFs() {
      wx.invoke(
        "openDefaultBrowser",
        {
          // 在默认浏览器打开redirect_uri，并附加code参数；也可以直接指定要打开的url，此时不会附带上code参数。
          url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wwb1448bd79e4dfde9&redirect_uri=http://crmapi.lyqswl.com&response_type=code&scope=snsapi_userinfo&agentid=1000007&state=STATE#wechat_redirect",
        },
        function (res) {
          console.log("res------------->", res);
          if (res.err_msg != "openDefaultBrowser:ok") {
            //错误处理
          }
        }
      );
    },
    // 切换系统
    system() {
      if (this.$store.state.systemLayer == "front") {
        this.$store.commit("setSystemLayer", "Administration");
      } else {
        this.$store.commit("setSystemLayer", "front");
      }
      this.$router.go(0);
    },
    // 新增跟进信息
    showFollow(obj) {
      this.$emit("dataAdd", "1");
    },
    // 新增联系人
    showEditer(obj) {
      this.$emit("dataAdd", "0");
    },
    // 消息通知跳转-订单列表
    linkOrder() {
      this.$router.push("/pay/OrderList");
    },
  },
};
</script>
<style scoped>
.limit {
  color: #cfcfcf;
  margin: 0 8px;
}
/* 左侧菜单路由跳转 */
.head_left {
  display: flex;
  align-content: center;
  align-items: center;
  float: left;
}
/********************************************************************* 消息提示 ************************************************************/
/* 通知 */
.nactione {
  margin-top: 8px;
  margin-right: 20px;
}
.hearts {
  right: 3px;
  top: -3px;
  width: 6px;
  height: 6px;
  background: #fc5531;
  border-radius: 8px;
  color: #fff;
  position: absolute;
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
}
/deep/.el-menu-item.is-active {
  color: #757993 !important;
  background-color: #fff !important;
}
/deep/.el-menu-item {
  color: #8a8989 !important;
}
/deep/ .el-menu-item i {
  color: #8a8989;
}
.el-menu.el-menu--horizontal {
  background-color: #fff;
  min-height: 28px;
  line-height: 28px;
  padding: 8px 11px;
  border-radius: 5px;
  overflow: hidden;
}
.notice {
  width: 89%;
  float: left;
  text-align: right;
  position: absolute;
}
.notice img {
  width: 1.35%;
  margin-top: 0.2rem;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
#head {
  overflow: hidden;
  display: flex;
  align-items: center;
  /* width: 240px; */
  width: 146px;
  float: right;
  margin-right: 2%;
}
.headImg {
  display: inline-block;
  width: 20%;
  /* width: 12%; */
  height: 20%;
  margin-left: 5%;
}
/* 用户名称样式 */
.user_name_c {
  padding: 0 0 0 5px;
  /* min-width:57px; */
  min-width: 45px;
  color: #8a8989;
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.submenu {
  width: 100px;
  /* margin-top: 11px; */
  background-color: #fff;
}
/deep/ .el-submenu__title {
  height: 29px;
  line-height: 29px;
  max-width: 40px;
  padding-right: 0;
  padding-left: 35px;
  margin-top: 4px;
  font-size: 14px;
  color: #8a8989 !important;
}
.buttonimg {
  height: 60px;
  background-color: transparent;
  border: none;
}
.showimg {
  width: 26px;
  height: 26px;
  position: absolute;
  top: 17px;
  left: 17px;
}
.showimg:active {
  border: none;
}
#set {
  background-color: #fff;
  border: 1px solid #fff;
}
/deep/ .el-submenu__title:hover {
  background-color: #fff;
}
</style>